# simple brainfuck interpreter
# NOTE: Here in brainfuck source we use curly brackets instead of square
# brackets because square brackets can't appear in comun source code (they're
# preprocessing delimiters) -- we  could make it work but the code wouldn't be
# so nice.

~cell:64          # tape
~command:8        # command analysing area
~stBackup:0

skip: # in: step (1 or -1), same bracket, opposite bracket
  1 # bracket count

  @'
    $3 $+stBackup
    $stBackup $3 = $stBackup $3 = -1 * + +  # update bracket count
  .

  ^ ^ ^ ^
.

bfRun:
  @'              # for each char
    $0>stBackup
    $:command     # copy to command area
    $command>0    # go to command area

    $0 "+" = ?
      $cell ++ $:cell
    ; $0 "-" = ?
      $cell -- $:cell
    ; $0 ">" = ?
      $>cell
    ; $0 "<" = ?
      $<cell
    ; $0 "." = ?
      $cell ->
    ; $0 "," = ?
      <- $:cell
    ; $0 "{" = ?

      $cell 0 = ?
        -1 "{" "}" skip
      .

    ; $0 "}" = ?

      $cell ?
        1 "}" "{" skip
      .

    . . . . . . . .

    $stBackup>0   # go back to the interpreted string

    ^
  .
.

0
",>,{<+>-}<------------------------------------------------." # add two ASCII digits 
bfRun 

